<script>
import outMain from "@/components/outMain.vue";
import elSelect from "@/components/public/elSelect.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { tkOperate, tkRecord } from "@/http/api";
export default {
  components: { outMain, elSelect },
  name: "",
  data() {
    return {
      tableData: [{}],
      statusArr: [
        { label: "全部", value: "" },
        { label: "待审核", value: "2" },
        { label: "退款中", value: "3" },
        { label: "已退款", value: "4" },
        { label: "已驳回", value: "5" },
      ],
      queryData: {
        order_number: "",
        examine_status: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    questCheck(data) {
      tkOperate(data).then((res) => {
        if (res.data.code == 1) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          this.getData();
        }
      });
    },
    checkStatus(row, type) {
      if (type == 3 || type == 4) {
        let str =
          type == 3
            ? "确定已完成此单退款?点击确认状态将更改为已成功退款。"
            : "确定同意退款此笔费用?点击确认状态将更改为等待退款中。";
        ElMessageBox.confirm(str, "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let data = {
            id: row.id,
            examine_status: type,
          };
          this.questCheck(data);
        });
      } else {
        ElMessageBox.prompt("请输入退款驳回理由?", "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then((value) => {
          let data = {
            id: row.id,
            examine_status: type,
            reason: value.value,
          };
          this.questCheck(data);
        });
      }
    },
    getData() {
      tkRecord(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>退款申请({{ total }})</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                v-model="queryData.order_number"
                placeholder="请输入订单号查询"
              />
            </el-form-item>
            <el-form-item>
              <elSelect
                placeholder="请选择退款状态"
                v-model="queryData.examine_status"
                :selectValue="queryData.examine_status"
                :selectArr="statusArr"
              ></elSelect>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          show-overflow-tooltip
          width="200"
          prop="order_number"
          label="订单编号"
        />
        <el-table-column
          prop="nick_name"
          show-overflow-tooltip
          label="用户昵称"
        />
        <el-table-column
          prop="pay_money"
          show-overflow-tooltip
          label="退款金额"
        />
        <el-table-column prop="staff" show-overflow-tooltip label="退款状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag type="warning" v-if="row.examine_status == 2"
                >待审核</el-tag
              >
              <el-tag v-if="row.examine_status == 3">退款中</el-tag>
              <el-tag type="success" v-if="row.examine_status == 4"
                >已退款</el-tag
              >
              <el-tag type="danger" v-if="row.examine_status == 5"
                >已驳回</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="expected_to_time"
          show-overflow-tooltip
          width="180"
          label="合同到期时间"
        />
        <el-table-column prop="reason" show-overflow-tooltip label="驳回原因" />
        <el-table-column
          prop="examine_time"
          show-overflow-tooltip
          width="180"
          label="操作时间"
        />
        <el-table-column
          width="180"
          prop="apply_time"
          show-overflow-tooltip
          label="申请时间"
        />
        <el-table-column prop="Name" width="180" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="blueText ctrlText"
                v-if="row.examine_status == 2"
                @click="checkStatus(row, 3)"
              >
                同意
              </div>
              <div
                class="redText ctrlText"
                v-if="row.examine_status == 2"
                @click="checkStatus(row, 5)"
              >
                驳回
              </div>
              <div
                class="blueText ctrlText"
                v-if="row.examine_status == 3"
                @click="checkStatus(row, 4)"
              >
                真实退款
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
